package study.polymorphic;

import lombok.SneakyThrows;

import java.lang.reflect.Method;

public class Test {
    @SneakyThrows
    public static void main(String[] args) {
        Class<?> appleCls = Class.forName("study.polymorphic.Apple");
        Class<?> appServiceCls = Class.forName("study.polymorphic.AppleService");

        Fruit apple = (Fruit) Class.forName("study.polymorphic.Apple").newInstance();
        apple.setName("apple");
        Method save = appleCls.getDeclaredMethod("setAppleAttr", String.class);
        save.invoke(apple, "this is appleAttr");

        FruitService service = (FruitService) appServiceCls.newInstance();

//                AppleService appleService = new AppleService();
//                appleService.save(apple);

        Method serviceSave = appServiceCls.getDeclaredMethod("save", appleCls);
        serviceSave.invoke(service, apple);
    }
}
